$(function(){
	
	var OKCH = {
		exit: {},
		datalist: {}
	};
	
	console.log("1");
	
	OKCH.exit.showform = function(e)
	{
		$("#funcs_exit").css("display", "none");
		$("#header_exit_b").css("display", "inline-block");
		e.preventDefault();
	}
	
	OKCH.exit.hideform = function(e)
	{
		$("#header_exit_b").css("display", "none");
		$("#funcs_exit").css("display", "inline-block");
		e.preventDefault();
	}
	
	OKCH.datalist.id = 0;
	
	OKCH.datalist.click = function(e)
	{
		var $this = $(this);
		if ( $this.hasClass("active") )
		{
			$this.removeClass("active");
			$("#header_ext_buttons").css("display", "none");
		}
		else
		{
			OKCH.datalist.id = $this.attr("data-id");
			$(".data-bind-row").removeClass("active");
			$("#header_ext_buttons").css("display", "inline-block");
			$this.addClass("active");
		}
	}
	
	console.log("2");
	
	// Binding exit buttons
	$("#funcs_exit").on("click", OKCH.exit.showform);
	$("#funcs_exit_no").on("click", OKCH.exit.hideform);
	$(".Table-list").on("click", ".data-bind-row", OKCH.datalist.click);
	
	
	console.log("3");
	
	// Checking for CSS 3D transformation support
	$.support.css3d = supportsCSS3D();
	
	var formContainer = $('#formContainer');
	
	// Listening for clicks on the ribbon links
	$('.flipLink').click(function(e){
		
		// Flipping the forms
		formContainer.toggleClass('flipped');
		
		// If there is no CSS3 3D support, simply
		// hide the login form (exposing the recover one)
		if(!$.support.css3d){
			$('#login').toggle();
		}
		e.preventDefault();
	});
	
	formContainer.find('form').submit(function(e){
		// Preventing form submissions. If you implement
		// a backend, you might want to remove this code
		
		
		//e.preventDefault();
	});
	
	
	// A helper function that checks for the 
	// support of the 3D CSS3 transformations.
	function supportsCSS3D() {
		var props = [
			'perspectiveProperty', 'WebkitPerspective', 'MozPerspective'
		], testDom = document.createElement('a');
		  
		for(var i=0; i<props.length; i++){
			if(props[i] in testDom.style){
				return true;
			}
		}
		
		return false;
	}
});
